package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分页查询菜品分类
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询菜品分类")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO){
        return categoryService.pageQuery(categoryPageQueryDTO);
    }

    /**
     * 新增菜品分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增菜品分类")
    public Result save(@RequestBody CategoryDTO categoryDTO){
        return categoryService.save(categoryDTO);
    }

    /**
     * 修改菜品分类
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改菜品分类")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        return categoryService.update(categoryDTO);
    }

    /**
     * 启用，禁用分类
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用，禁用分类")
    public Result setStatus(@PathVariable Integer status,Long id){
        return categoryService.setStatus(status,id);
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "根据类型查询分类")
    public Result<List<Category>> selectByType(Integer type){
        return categoryService.selectByType(type);
    }

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "根据id删除分类")
    public Result deleteById(Long id){
        return categoryService.deleteById(id);
    }
}
